package com.spring.demo.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import org.hibernate.validator.constraints.NotEmpty;
import org.joda.time.DateTime;

@Entity
@Table(name = "TB_USER")
public class User implements AuditablePoEntity<Long>, Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID_USER",unique = true, nullable = false, columnDefinition = "int(11) unsigned", length = 11)	
	private Long id;
	
	@NotEmpty(message = "Login Name is not blank")
	@Column(name = "VR_USER_LOGINNAME", nullable = true, length = 50)
	private String loginName;
	
	@NotEmpty(message = "Password is not blank")
	@Column(name = "VR_USER_PASSWORD", nullable = true, length = 50)
	private String password;
	
	@NotEmpty(message = "User Name is not blank")
	@Column(name = "VR_USER_NAME", nullable = true, length = 50)
	private String userName;
	
	@Version
	@Column(name = "I_USER_VERSION",columnDefinition = "smallint(6) default 0", nullable = false, length = 6)	
	private Integer version;
	
	@NotEmpty
	@Column(name = "VR_USER_CREATOR", nullable = true, length = 150)
	private String createdBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "DT_USER_CREATION")
	private Date createdDate;

	@NotEmpty
	@Column(name = "VR_USER_MODIFIER", nullable = true, length = 150)
	private String lastModifiedBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "DT_USER_MODIFICATION")
	private Date lastModifiedDate;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public DateTime getCreatedDate() {
		return null == createdDate ? null : new DateTime(createdDate);
	}

	public void setCreatedDate(final DateTime createdDate) {
		this.createdDate = null == createdDate ? null : createdDate.toDate();
	}

	public String getLastModifiedBy() {
		return lastModifiedBy;
	}

	public void setLastModifiedBy(String lastModifiedBy) {
		this.lastModifiedBy = lastModifiedBy;
	}

	public DateTime getLastModifiedDate() {
		return null == lastModifiedDate ? null : new DateTime(lastModifiedDate);
	}

	public void setLastModifiedDate(final DateTime lastModifiedDate) {
		this.lastModifiedDate = null == lastModifiedDate ? null : lastModifiedDate.toDate();
	}

}
